<!--
 * @Author: 李小晴 2689279066@qq.com
 * @Date: 2022-06-13 09:11:01
 * @LastEditors: 李小晴 2689279066@qq.com
 * @LastEditTime: 2022-06-14 10:38:55
 * @FilePath: \admin\src\views\Manager\components\Write.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<script setup lang="ts">
import { Form } from '@/components/Form'
import { useForm } from '@/hooks/web/useForm'
import { PropType, reactive, watch } from 'vue'
// import { TableData } from '@/api/table/types'
import { required } from '@/utils/formRules'

const props = defineProps({
  currentRow: {
    type: Object as PropType<Nullable<any>>,
    default: () => null
  },
  formSchema: {
    type: Array as PropType<FormSchema[]>,
    default: () => []
  }
})

const rules = reactive({
  // admin_id: [required],
  // dept_id: [required],
  // role_id: [required],
  username: [required],
  nickname: [required],
  password: [required],
  avatar: [required],
  email: [required],
  mobile: [required]
  // is_stop: [required]
})

const { register, methods, elFormRef } = useForm({
  schema: props.formSchema
})

watch(
  () => props.currentRow,
  (currentRow) => {
    if (!currentRow) return
    const { setValues } = methods
    setValues(currentRow)
  },
  {
    deep: true,
    immediate: true
  }
)

defineExpose({
  elFormRef,
  getFormData: methods.getFormData
})
// console.log(methods.getFormData, 'methods.getFormData')
</script>

<template>
  <Form :rules="rules" @register="register" />
</template>
